import React from "react";
import { findById, remove } from "../../services/student";
export default function (props) {
    
    const handleEdit = async (id) => {
        let data = await findById(id);
        props.setStudent(data);
    }
    const handleDelete = async (id) => {
        await remove(id);
        props.show();
    }
    return (
        <table border="1">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {props.students.map((item) => <tr key={item._id}>
                    <td>{item.name}</td>
                    <td>{item.gender}</td>
                    <td>{item.age}</td>
                    <td>
                        <input type="button" value="修改" onClick={() => handleEdit(item._id)}/>
                        <input type="button" value="删除" onClick={() => handleDelete(item._id)} />
                    </td>
                </tr>)}
                
            </tbody>
        </table>
    );
}
